﻿Public Class FrmValidacion

    Private Sub txtNombre_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles txtNombre.Validating
        If Not IsNombreValid() Then
            e.Cancel = True
            errorProvider.SetError(txtNombre, "No debe haber un nro")
        Else
            errorProvider.SetError(txtNombre, Nothing)
        End If
    End Sub

    Private Sub txtNroDoc_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles txtNroDoc.Validating
        If Not IsNroDocValid() Then
            e.Cancel = True
            errorProvider.SetError(txtNroDoc, "No debe haber una letra")
        Else
            errorProvider.SetError(txtNroDoc, Nothing)
        End If
    End Sub

    Private Sub txtApellido_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles txtApellido.Validating
        If Not IsApellidoValid() Then
            e.Cancel = True
            errorProvider.SetError(txtApellido, "No debe haber un nro")
        Else
            errorProvider.SetError(txtApellido, Nothing)
        End If
    End Sub

    Private Sub btnAceptar_Click(sender As System.Object, e As System.EventArgs) Handles btnAceptar.Click
        If IsFormValid() Then
            MessageBox.Show("Aceptar")
            Me.Close()
        Else
            MessageBox.Show("No es válido")
        End If
    End Sub

    Private Function IsNombreValid() As Boolean
        Return IsOnlyText(txtNombre.Text)
    End Function

    Private Function IsApellidoValid() As Boolean
        Return IsOnlyText(txtApellido.Text)
    End Function

    Private Function IsNroDocValid() As Boolean
        Return IsOnlyNumber(txtNroDoc.Text)
    End Function

    Private Function IsOnlyText(ByVal text As String) As Boolean
        Return text.Contains("a")
    End Function

    Private Function IsOnlyNumber(ByVal text As String) As Boolean
        Return text.Contains("0")
    End Function

    Private Function IsFormValid() As Boolean
        Return IsNombreValid() AndAlso IsApellidoValid() AndAlso IsNroDocValid()
    End Function

    Private Sub btnCancelar_Click(sender As System.Object, e As System.EventArgs) Handles btnCancelar.Click
        Me.Close()
    End Sub
End Class